﻿$(document).ready(function () {
    $("#btnAddDesignVectorConfirm").click(function (e) {
        //upload the image (by submiting the form)
        $("#frmUploadImage").submit();
    });

    //when the form has been finished proccesing (and the iframe is being load)
    $("#UploadIframe").load(function () {
        var imageUrl = $(this).contents().text();
        $("#ThumbnailUrl").val(imageUrl);

        var data = $("#frmAddDesignVector").serialize();
        $.validator.unobtrusive.parse($("#frmAddDesignVector"));

        var fileName = $("#frmUploadImage [name='file']").val();

        if ($("#frmAddDesignVector").valid()) {
            if (fileName != "") {
                var parts = fileName.split('.');
                var extension = parts[parts.length - 1];

                if (extension == "swf") {
                    var mainDialog = updateDialog("מדבקה חדשה", "300", "550");

                    //Invoke AJAX method to add the vector to DB
                    $.post(pathPrefix + "DesignVectors/AddDesignVector", data, function (result) {
                        closeDialog();

                        BindCategories();
                    }, "json");
                }
            }
        }
    });
});